#include<iostream>
#include<string>
#include<sys/types.h>
#include<sys/stat.h>
#include"comm.hpp"
#include<fcntl.h>
#include<unistd.h>
int main()
{
    int fd=open(FIFO_FILE,O_WRONLY);
    if(fd==-1)
    {
        perror("open fail");
        return 1;
    }
    std::cout<<"open sucess"<<std::endl;
    int n=0;
    pid_t id=getpid();
    while(1)
    {
        std::cout<<"Please Enter:"<<std::endl;
        std::string message;
        std::cin>>message;
        message+=",message number:"+std::to_string(n++)+", ["+std::to_string(id)+"]";
        //写入message：
        int ret=write(fd,message.c_str(),message.size());
        if(ret<0)
        {
            perror("write fail");
            break;
        }
    }

    close(fd);
    return 0;
}